package com.bigdata.controller;

import com.bigdata.pojo.Article;
import com.bigdata.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Iterator;
import java.util.List;

@Controller
public class BlogController {

    @Autowired
    private ArticleService articleService;

    @RequestMapping("/index")
    public String indexArticle(Model model, @RequestParam(value = "pageNum", defaultValue = "0") int pageNum, @RequestParam(value = "pageSize", defaultValue = "2") int pageSize){
        Page<Article> articlePage = articleService.findAll(pageNum, pageSize);
        System.out.println("总页数" + articlePage.getTotalPages());
        System.out.println("当前页是：" + pageNum);

        System.out.println("分页数据：");
        Iterator<Article> u = articlePage.iterator();
        while (u.hasNext()){
            System.out.println(u.next().toString());
        }
        model.addAttribute("articleList",articlePage);
        return "client/index";
    }
}
